﻿<!DOCTYPE html>
@{ 
    Layout = "/Views/Shared/_level1.cshtml";
}
<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <meta name="renderer" content="webkit">
    <link href="/SiteUI/Register/Register.css" rel="stylesheet" />
</head>
<body>

    <div class="view_fix" id="viewRegister">
        <div class="row step2" id="RealNameTitle">实名认证</div>
        <div class="row" id="vr-tip">
            您在本平台的行为将代表企业的利益，为保证数据安全，我们需要核实您的真实身份信息
        </div>
        <div class="row">
            <div class="col-lg-4 col-lg-offset-4" id="gbsj">
                <strong>手机号码：</strong>
                <span id="lblPhone"></span>
                <div>&nbsp;</div>
            </div>
        </div>
        <div class="row">
            <div class="col-lg-4 col-lg-offset-4">
                <h5>真实姓名：</h5>
                <input maxlength="10" id="txbName" placeholder="请输入您的真实姓名" />
            </div>
            <div class="col-lg-4">
                <h5>&nbsp;</h5>
                <div id="it-name" class="inputTip"></div>
            </div>
        </div>
        <div class="row">
            <div class="col-lg-4 col-lg-offset-4">
                <h5>业务邮箱：</h5>
                <input maxlength="50" id="txbMail" placeholder="请输入您常用电子邮箱" />
            </div>
            <div class="col-lg-4">
                <h5>&nbsp;</h5>
                <div id="it-mail" class="inputTip"></div>
            </div>
        </div>
        <div class="row">
            <div class="col-lg-4 col-lg-offset-4">
                <h5>身份证号：</h5>
                <input maxlength="18" id="txbIdentity" placeholder="公民身份证号码" />
            </div>
            <div class="col-lg-4">
                <h5>&nbsp;</h5>
                <div id="it-identity" class="inputTip"></div>
            </div>

        </div>
        <div class="row">
            <div class="col-lg-4 col-lg-offset-4">
                <h5>认证资料：</h5>
            </div>
            <div class="col-lg-2 col-lg-offset-4 picUpload" id="picIDCard-face">
                <img src="/SiteUI/Imgs/idcard-example-face.jpg" />
            </div>
            <div class="col-lg-5" id="face_reminder">
                <strong>点击左侧图片替换您自己的照片</strong><a class="LinkTo" target="_blank" href="/SiteUI/Imgs/idcard-example-face-big.jpg">点这里查看样例</a>
                <br />
                免冠(建议未化妆)，手持本人证件；
                <br />
                所有信息清晰可见，必须能看得清证件号,不得做任何修改。；
                <br />
                照片支持.jpg .jpeg .bmp .gif .png格式照片，大小不超过8M。
            </div>
            <div class="col-lg-4 col-lg-offset-4">
                <div id="it-idcard" style="margin:0" class="inputTip"></div>
            </div>
        </div>
        <div class="row" id="it-feedback" style="display:none">
            <div class="col-lg-4 col-lg-offset-4">
                <div id="txb-feedback"><h6>意见反馈：</h6><span></span></div>
            </div>

        </div>
        <div class="row" id="certificationState">
            <div class="col-lg-4 col-lg-offset-4 button btn-big" id="btnApply">
                提交认证申请
            </div>

        </div>
        <div class="row">
            <div class="col-lg-8 col-lg-offset-2">
                <div id="face_subbtn">
                    1、保密承诺：您的身份信息仅用于天联云企业用户实名认证使用，天联云不会将个人身份信息用作其他商业用途；<br />
                    2、审核时限：个人实名认证时限为5个工作日内。
                </div>
            </div>
        </div>
    </div>

    <script>
        var AcntCertify = {
            certify:{
                phone:null,
                realname:null,
                email:null,
                socialid:null,
                idcardface: null,
                updatetime: null,
                status: null,
                feedback:null
            },
            picFace:null,
            mailFormat:/^([0-9A-Za-z\-_\.]+)@@([0-9a-z]+\.[a-z]{2,3}(\.[a-z]{2})?)$/, //邮箱校验正则
            identityFormat: /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/, //身份证校验正则
            onGetCertifyEnd: function (rtn) {
                if (rtn.IsPositive) {
                    AcntCertify.certify = rtn.Data;
                    switch (AcntCertify.certify.status) {
                        case "Pending": //审核中
                            AcntCertify.CertificationVerify();
                            break;
                        case "Aborted": //审核不通过
                            AcntCertify.againCertification();
                            break; 
                        case "Completed":  //审核通过
                            AcntCertify.CertificationSuccess();
                            break;
                    }
                }
                else {
                    //无认证记录
                }
            },
            onPicFaceChange: function (ev) {
                $("#it-idcard").vl("").removeClass("error");
                switch (ev.Status) {
                    case "imageLoaded":
                        $("#picIDCard-face>img").attr("src", ev.Item.thumbnail);
                        break;
                    case "uploadProcessing":
                        $("#it-idcard").removeClass("error,success").vl("正在上传...");
                        break;
                    case "uploadEnd":
                        $("#it-idcard").removeClass("error").addClass("success").vl("上传成功");
                        AcntCertify.certify.idcardface = ev.Item.Result.path;
                        break;
                }
            },
            applyCertify: function () {
                if (AcntCertify.checkMail()& AcntCertify.checkIdentity()&AcntCertify.checkName()&AcntCertify.checkIdPic()) {
                    $.post("/MyBiz/ApplyCertify", AcntCertify.certify, function (rtn) {
                        if (rtn.IsPositive) {
                            success("成功", "您的实名认证申请已提交").on("disposed", function (ev) { window.history.go(-1); });
                        }
                        else {
                            error("失败", ErrFormate(res_sobiz, rtn.ErrorSrc, rtn.ErrorCode, rtn.Error));
                        }
                    });
                }
            },
            checkMail: function () {
                var mail = $("#txbMail").vl();
                if (!AcntCertify.mailFormat.test(mail)) {
                    $("#it-mail").vl("邮箱格式不正确").addClass("error");
                    return false;
                } else {
                    $("#it-mail").removeClass("error").vl("");
                    AcntCertify.certify.mail = $("#txbMail").vl();
                    return true;
                }
            },
            checkIdentity: function () {
                var sid = $("#txbIdentity").vl();
                if (!AcntCertify.identityFormat.test(sid)) {
                    $("#it-identity").vl("身份证格式不正确").addClass("error");
                    return false;
                } else {
                    $("#it-identity").removeClass("error").vl("");
                    AcntCertify.certify.socialid = sid;
                    return true;
                }
            },
            checkName: function () {
                var n = $("#txbName").vl();
                if (n.length <= 0) {
                    $("#it-name").vl("请输入您的真实姓名").addClass("error");
                    return false;
                }
                else {
                    $("#it-name").vl("").removeClass("error");
                    AcntCertify.certify.name = n;
                    return true;
                }
            },
            checkIdPic: function () {
                if (AcntCertify.certify.idcardface == null) {
                    if (AcntCertify.certify.idcardpic == null) {
                        $("#it-idcard").vl("请上传符合要求的图片").addClass("error");
                        return false;
                    } else {
                        $("#it-idcard").vl("").removeClass("error");
                        AcntCertify.certify.idcardface = AcntCertify.certify.idcardpic;
                        return true;
                    }
                }
                else {
                       $("#it-idcard").vl("").removeClass("error");
                      return true;
                }
            },
            CertificationVerify: function () {
                $("#txbName").vl(AcntCertify.certify.realname).attr('disabled', 'true');
                $("#txbMail").vl(AcntCertify.certify.email||User.email).attr('disabled', 'true');
                $("#txbIdentity").vl(AcntCertify.certify.socialid).attr('disabled', 'true');
                $("#picIDCard-face>img").attr("src",AcntCertify.certify.idcardpic);
                AcntCertify.picFace.disable();
                $("#btnApply").remove();
                $("#face_reminder").remove();
                $("#certificationState").append("<div class='col-lg-4 col-lg-offset-4' id='certificationTime'><strong>认证审核中</strong><br />提交认时间：" + new Date(AcntCertify.certify.updatetime).format("yyyy/MM/dd hh:mm:ss") + "</div>");
            },
            CertificationSuccess: function () {
                $("#txbName").vl(AcntCertify.certify.realname).attr('disabled', 'true');
                $("#txbMail").vl(AcntCertify.certify.email || User.email).attr('disabled', 'true');
                if (AcntCertify.certify.socialid!=null) {
                   // AcntCertify.certify.socialid
                    var soc = "123456789012345678";
                    soc = soc.substring(0, 4) +"*****"+ soc.substring(soc.length - 4, soc.length);
                    $("#txbIdentity").vl(soc).attr('disabled', 'true');
                }
                $("#picIDCard-face>img").attr("src", "" + AcntCertify.certify.idcardpic + "");
                AcntCertify.picFace.disable();
                $("#btnApply").remove();
                $("#face_reminder").remove();
            },
            againCertification: function () {
                $("#txbName").vl(AcntCertify.certify.realname);
                $("#txbMail").vl(AcntCertify.certify.email);
                $("#txbIdentity").vl(AcntCertify.certify.socialid);
                $("#picIDCard-face>img").attr("src", "" + AcntCertify.certify.idcardpic + "");
                $("#it-feedback").show();
                $("#txb-feedback>span").vl(AcntCertify.certify.feedback);
                $("#btnApply").vl("重新认证申请");
            }
        }

        $(function () {
            //获得用户信息并进行相对应的操作
            $.getJSON("/MyBiz/GetCertification", {}, AcntCertify.onGetCertifyEnd);

            $("body").on("UserReady", function (ev) {
                $("#lblPhone").vl(User.mphone);
                AcntCertify.certify.phone = User.mphone;
            });

            $("#txbName").blur(AcntCertify.checkName);
            $("#txbMail").blur(AcntCertify.checkMail);
            $("#txbIdentity").blur(AcntCertify.checkIdentity);

            $("#btnApply").on("click", AcntCertify.applyCertify);

            AcntCertify.picFace = new LiberUI.Uploader("#picIDCard-face")
                                             .option("FileType", "image/*")
                                             .option("MaxSize", 10240000)
                                             .update();
            AcntCertify.picFace.on("change", AcntCertify.onPicFaceChange);
        })
    </script>
</body>
</html>

